package edu.scsu.csci.config;

import edu.scsu.csci.IConverter;
import edu.scsu.csci.converter.ConvertorRegistry;
import edu.scsu.csci.util.ReflectionUtil;


/**
 * @viz.diagram ConfigConvertorWrapper.tpx
 */
public class ConfigConvertorWrapper implements Item{
	
	/**
	 * the type of objects the convertor is capable of converting.
	 */
	private Class<?> objectType;
	
	/**
	 * the implemtaion for the convetor.
	 */
	private Class<? extends IConverter> convertorClazz;

	/**
	 * 
	 */
	public ConfigConvertorWrapper() {}

	/**
	 * @param type
	 * @param convertorClazz
	 */
	public ConfigConvertorWrapper(Class<?> type, Class<? extends IConverter> convertorClazz) {
		this.objectType = type;
		this.convertorClazz = convertorClazz;
	}

	
	/**
	 * Returns convertorClazz.
	 * @return Returns convertorClazz.
	 */
	public Class<? extends IConverter> getConvertorClazz() {
		return convertorClazz;
	}

	
	/**
	 * @param convertorClazz The convertorClazz to set.
	 */
	public void setConvertorClazz(Class<? extends IConverter> convertorClazz) {
		this.convertorClazz = convertorClazz;
	}

	
	/**
	 * Returns type.
	 * @return Returns type.
	 */
	public Class<?> getObjectType() {
		return objectType;
	}

	
	/**
	 * @param type The type to set.
	 */
	public void setObjectType(Class<?> type) {
		this.objectType = type;
	}

	public void register() throws ConfigurationException {
		ConvertorRegistry.getInstance().register(this.objectType, ReflectionUtil.instantiate(this.convertorClazz));
	}
}
